#include "standard-table-model.h"
#include "standard-table-section-model.h"

StandardTableSectionModel::StandardTableSectionModel(QObject *parent) :
    AbstractSectionModel(parent), m_internalModel(new StandardTableModel(this)), m_idColumnCount(1)
{
}

QVariant StandardTableSectionModel::id (int row, int column) const
{
    return m_internalModel->index(row, column).data(Qt::UserRole);
}

QMap<int,QAbstractItemDelegate*> StandardTableSectionModel::delegates() const
{
    return m_delegates;
}

QList<bool> StandardTableSectionModel::permissions() const
{
    return QList<bool>() << true << true << true;
}

int StandardTableSectionModel::rowCount(const QModelIndex &parent) const
{
    return m_internalModel->rowCount(parent);
}

int StandardTableSectionModel::columnCount(const QModelIndex &parent) const
{
    return m_internalModel->columnCount(parent) - m_idColumnCount;
}

QVariant StandardTableSectionModel::data(const QModelIndex &index, int role) const
{
    return m_internalModel->data(m_internalModel->index(index.row(), index.column() + m_idColumnCount), role);

}

QVariant StandardTableSectionModel::headerData(int section, Qt::Orientation orientation, int role) const
{
    if (orientation == Qt::Horizontal)
        return m_internalModel->headerData(section + m_idColumnCount, orientation, role);
    else
        return m_internalModel->headerData(section, orientation, role);
}

bool StandardTableSectionModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
    return m_internalModel->setData(m_internalModel->index(index.row(), index.column() + m_idColumnCount), value, role);
}

bool StandardTableSectionModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
{
    return m_internalModel->setHeaderData(section + m_idColumnCount, orientation, value, role);
}

bool StandardTableSectionModel::insertRows (int row, int count, const QModelIndex &parent)
{
    beginInsertRows(parent, row, row + count - 1);
    bool result = m_internalModel->insertRows(row, count, parent);
    endInsertRows();
    return result;
}

bool StandardTableSectionModel::removeRows(int row, int count, const QModelIndex &parent)
{
    beginRemoveRows(parent, row, row + count - 1);
    bool result = m_internalModel->removeRows(row, count, parent);
    endRemoveRows();
    return result;
}
